#include "touch.h"


int touch_fd;

// int x,y,t;
void touchInit()
{
     //1. 访问触摸屏设备文件
    
	touch_fd = open("/dev/input/event0",O_RDONLY);
	if(touch_fd < 0)
		printf("open event0 error!\n");
}

void touchExit()
{
    close(touch_fd);
}



void touching()
{

	//2. 读取文件数据
	struct input_event buf;
	read(touch_fd,&buf,sizeof(buf));


    if (buf.type==EV_ABS&&buf.code==ABS_X)
    {
        x=buf.value;
    }
    if (buf.type==EV_ABS&&buf.code==ABS_Y)
    {
        y=buf.value;
    }

    if(buf.type==EV_KEY&&buf.code==BTN_TOUCH&&buf.value==1)
    {
      t=buf.value;
 
      //printf("(%d,%d,%d)\n",x,y,buf.value);
    }
      

    if(buf.type==EV_KEY&&buf.code==BTN_TOUCH&&buf.value==0)
    {
      t=buf.value;
 
      //printf("(%d,%d,%d)\n",x,y,buf.value);
    }
      

    

    
    //滑动坐标
    /*
    printf("x=%d y=%d\n",x,y);
    */

}

	